﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Dune2013
{
    public class ConstruirBehavior:Behavior
    {
        int tiempoConstruccion = 0;
        public float tiempoTotalConstruccion;
        float buildDeltaScale;// = 0.005f;
        float maxScale;
        Node pozoActual;
        public ConstruirBehavior(Node pozo, float tiempoTotalConstruccion)
        {
            this.pozoActual = pozo;
            maxScale = pozoActual.scale;
            this.tiempoTotalConstruccion = tiempoTotalConstruccion;
            this.buildDeltaScale = maxScale / (1 + tiempoTotalConstruccion / 16);//1/tiempoTotalConstruccion*maxScale; //para 3000 es 0.005f
            NodeManager.getInstance().makeBuildingWell(pozoActual);
            
            pozoActual.scale = buildDeltaScale;
        }
        public override void enter(Actor act)
        {
            base.enter(act);
        }
        public override void execute(int dTime,Actor act)
        {
            System.Console.WriteLine("Plantando");
            tiempoConstruccion += dTime;
            pozoActual.scale += pozoActual.scale < maxScale - buildDeltaScale ? buildDeltaScale : maxScale - pozoActual.scale; //hago que crezca hasta el tamaño normal
            if (tiempoConstruccion >= tiempoTotalConstruccion)
            {
                tiempoConstruccion = 0;
                if( pozoActual.oil<=0 )
                    NodeManager.getInstance().makeEmpty(pozoActual);
                else
                    NodeManager.getInstance().makeWell(pozoActual);
                act.changeBehavior(new IrCosecharBehavior());
            }
            base.execute(dTime,act);
        }
        public override void exit(Actor act)
        {
            System.Console.WriteLine("deje de plantar");
            base.exit(act);
        }
        public override Behavior getIrABehavior()
        {
            return new IrCosecharBehavior();
        }
    }
}
